apiready = function(){
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service"],function(V,$api,$,$app,service){
	var vm = {
		el: '.city-select-wrap',
	  	data: {
	  		province_id: '',
	  		city_id: '',
	  		district_id: '',
	    	name_p: '请选择',
	    	name_c: '请选择',
	    	name_d: '请选择',
	    	activeIndex: 0,
	    	city: [],
	    	is_select: false
	  	},
	  	methods:{
	  		init: function(){
	  			this.cityAjax(0);
	  		},
	  		//--城市请求
	  		cityAjax: function(pid){
	  			var self = this;
	  			$app.ajax(service.chinaCity,{
					data: {
						values: {
							pid: pid,
							mask:'none'
						}
					}
				},function (res) {
					if(res.code == 0){
						self.city = res.data;
						self.is_select = true;
					}else{
						alert(res.message || res.msg);
					}
				});
	  		},
			//--关闭城市选择
			addressAddCitySelectClose: function(){
				this.btnKeyBack(1,'已取消选择',"");
			},
			//--获取城市选择id
			getCityId: function(et){
				if(!this.is_select){
					return;
				}
				var self = this;
				var id = +et.currentTarget.dataset.id;
				var name = et.currentTarget.dataset.name;
				this.index = +et.currentTarget.dataset.index;
				switch(this.index){
					case 0:
						this.is_select = false;
						this.province_id = id;
						this.name_p = name;
						this.activeIndex = 1;
						this.cityAjax(id);
						break;
					case 1:
						this.is_select = false;
						this.city_id = id;
						this.name_c = name;
						this.activeIndex = 2;
						this.cityAjax(id);
						break;
					case 2:
						this.district_id = id;
						this.name_d = name;
						this.activeIndex = 2;
						self.btnKeyBack(0,'城市选择成功',{
							province_id: self.province_id,
					  		city_id: self.city_id,
					  		district_id: self.district_id,
					    	province_name: self.name_p,
					    	city_name: self.name_c,
					    	district_name: self.name_d,
					    	full_name: self.name_p+' '+self.name_c+' '+self.name_d,
					    	full_id: self.province_id+','+self.city_id+','+self.district_id
						});
						break;
					default:
						break;
				}
			},
	  		cityName_p: function(et){
	  			this.activeIndex = 0;
	  			this.name_p = this.name_c = this.name_d = '请选择';
	  			this.cityAjax(0);
	  		},
	  		cityName_c: function(et){
	  			this.activeIndex = 1;
	  			this.name_c = this.name_d = '请选择';
	  			this.cityAjax(this.province_id);
	  		},
	  		cityName_d: function(et){
	  			this.name_d = '请选择';
	  			this.activeIndex = 2;
	  			this.cityAjax(this.city_id);
	  		},
	  		btnKeyBack: function(code,msg,data){
	  			api.sendEvent({
					name:'citySelect_',
					extra:{
						code: code,
						msg: msg,
						data: data
					}
				});
				$api.setTimeout(function(){
					api.closeFrame();
				},200);
	  		}
	  	},
	  	mounted:function() {
	  		var self = this;
	  		api.setStatusBarStyle({
				style: 'dark',
				color: 'transparent'
			});
			//--点击上面按钮返回
			$api.addEvt($api.dom('#btn-back'), 'click', function() {
	            self.btnKeyBack(1,'已取消选择',"");
	        });

			//--返回键
			api.addEventListener({
				name: 'keyback'
			},function(ret, err){
				self.btnKeyBack(1,'已取消选择',"");
			});
	  	},
	  	created: function(){
	  		this.init();
	  	}
	};
	var even = function() {}
	var newVue = new Vue(vm);
	even();
});
}
